//
//  InfoServiceController.m
//  BigToBig
//
//  Created by 毛丽媛 on 16/7/28.
//  Copyright © 2016年 cn.cloudtp. All rights reserved.
//

#import "InfoServiceController.h"
#import "HomeFunctionView.h"
#import "InfoServicetableViewCell.h"
#import "InfoServiceDetailViewController.h"

@interface InfoServiceController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic , strong)UISearchBar *searchBar;
@property (nonatomic , strong)HomeFunctionView *homeFunctionView;
@property (nonatomic , strong)UITableView *mainTableView;
@end

@implementation InfoServiceController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self setBackBar];
    self.view.backgroundColor = [UIColor whiteColor];
    self.searchBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 64)];
    //    [self.navigationController.navigationBar addSubview:self.searchBar];
    self.navigationItem.titleView = self.searchBar;
    self.searchBar.placeholder = @"搜索项目";
    // 创建功能区(排序 and 筛选)
    self.homeFunctionView = [[HomeFunctionView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 40)];
    [self.view addSubview:self.homeFunctionView];

    // 创建mainTableView
    self.mainTableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 40, kScreenWidth, kScreenHeight - 64 - 40)];
    [self.view addSubview:self.mainTableView];
    self.mainTableView.delegate = self;
    self.mainTableView.dataSource = self;
    self.mainTableView.separatorStyle = NO;
    self.mainTableView.bounces = NO;
    
    [self.mainTableView registerClass:[InfoServicetableViewCell class] forCellReuseIdentifier:@"cell"];
    
    
}

#pragma mark - tableView 代理方法
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 110;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    InfoServicetableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.describeLabel.text = @"回家方便的施工不都是发介绍的回复大家好";
    cell.cityLabel.text = @"大连";
    cell.phoneLabel.text = @"18845151234";
    cell.selectionStyle = UITableViewCellSelectionStyleNone;

    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    InfoServiceDetailViewController *serDetVC = [[InfoServiceDetailViewController alloc] init];
    [self.navigationController pushViewController:serDetVC animated:YES];
}


#pragma mark 导航栏左右Button
- (void)setBackBar{
    
    BackButton *backBtn=[BackButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(0, 0, 44, 44);
    [backBtn addTarget:self action:@selector(backController:) forControlEvents:UIControlEventTouchUpInside];
    [backBtn setImage:[UIImage imageNamed:@"返回"] forState:UIControlStateNormal];
    [backBtn.imageView setContentMode:UIViewContentModeLeft];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:backBtn];
    [self.navigationItem setHidesBackButton:YES animated:YES];
    
    
}

- (void)backController:(UIButton *)button{
    self.hidesBottomBarWhenPushed = YES;
    [self.navigationController popViewControllerAnimated:YES];
    self.tabBarController.tabBar.hidden = NO;
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
